package com.ydlclass.netty;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

/**
 * @author Knife
 */
public class MyWatcher implements Watcher {
    @Override
    public void process(WatchedEvent event) {
        // event 是事件，
        // 判断事件类型，连接类型的事件
        if (event.getType() == Event.EventType.None){
            if (event.getState() == Event.KeeperState.SyncConnected){
                System.out.println("zookeeper连接成功");
            } else if (event.getState() == Event.KeeperState.AuthFailed){
                System.out.println("认证失败");
            } else if (event.getState() == Event.KeeperState.Disconnected){
                System.out.println("断开状态");
            } else if (event.getState() == Event.KeeperState.Closed){
                System.out.println("节点关闭了");
            }
        } else if (event.getType() == Event.EventType.NodeDeleted){
            System.out.println("节点删除乐");
        } else if (event.getType() == Event.EventType.NodeCreated){
            System.out.println("节点创建了");
        } else if (event.getType() == Event.EventType.NodeDataChanged){
            System.out.println("节点数据改变了");
        } else if (event.getType() == Event.EventType.NodeChildrenChanged){
            System.out.println("子节点数据改变了");
        }
    }
}
